package com.atung.parking.mapstruct;

import com.atung.parking.entity.BusParkingIotFranchise;
import com.atung.parking.entity.BusSuperUser;
import com.atung.parking.export.FranchiseExportVO;
import com.atung.parking.export.SuperAdminExportVO;
import com.atung.parking.response.page.FranchiseResponse;
import com.atung.parking.response.page.SuperUserResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Mapper(componentModel = "spring")
public interface ParkingIotFranchiseConverter {
    @Mapping(target = "creatorTime", source = "creatorTime", qualifiedByName = "timestampToString")
    FranchiseResponse toResponse(BusParkingIotFranchise busParkingIotFranchise);

    FranchiseExportVO toExportVo(BusParkingIotFranchise busParkingIotFranchise);
    @Named("timestampToString")
    default String timestampToString(String timestamp) {
        if (timestamp == null || timestamp.isEmpty()) {
            return null;
        }
        try {
            long timeInMillis = Long.parseLong(timestamp);
            Date date = new Date(timeInMillis);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(date);
        } catch (NumberFormatException e) {
            // 如果timestamp不是有效的长整型数字字符串，返回null或抛出异常
            return null;
        }
    }
}
